#include "zf_common_headfile.h"
#ifndef FUNVTION_H_
#define FUNVTION_H_
// #include "Camera.h"
// #include <opencv2/opencv.hpp>
// #include <stdint.h>
// extern cv::Mat colorImage;
// void OpenCV_Inverse(void);//将处理后的图像经过OpenCV逆转
// void OpenCV_DrawLine(uint8_t (* ipts)[2],uint8_t * ipts_num,uint8_t blue,uint8_t green,uint8_t red);
// void OpenCV_Transfer(uint8_t mt9v03x_image[][MT9V03X_W],const cv::Mat& sourceImage);//opencv数据转换


#ifndef MIN_DEFINED
#define MIN_DEFINED
#define min(a,b) (a<b?a:b)
#endif

#ifndef MAX_DEFINED
#define MAX_DEFINED
#define max(a,b) (a>b?a:b)
#endif

#ifndef PI_DEFINED
#define PI_DEFINED
#define PI                  ( 3.1415926535898 )
#endif


#define OVER_STEP_R(a) (a>(COL-1)?COL-1:a)
#define OVER_STEP_L(a) (a<0?0:a)
#define func_limit_ab(a,small,big) max(small,min(a,big))
#define limit_min(a,min) (a<min?min:a)
#define limit_max(a,max) (a>max?max:a)
#define Diff_Ratio(a,b)  (((a)-(b))<<7)/((a+b)+1)


void copyArrays(uint8_t (*A)[2], uint8_t (*B)[2], uint8_t Start_A, uint8_t End_A,uint8_t Start_B);


void Patch_Line_Points2(uint8_t x,uint8_t y,uint8_t D,uint8_t (*ipts)[2],uint8_t * ipts_num);

//两点斜率
float Slope_2Points(uint8_t big,uint8_t small,uint8_t (*ipts));

//斜距计算
float Intercept_Calculate(uint8_t y,uint8_t (*ipts),float slope);

void Patch_Line_Points(uint8_t begin_y,uint8_t end_y,float slope,float intercept,uint8_t (*ipts));
void fit_poly(uint8_t big_y,uint8_t small_y,float a,float b,float c, unsigned char (*ipts));
//最小二乘法斜率
float Slope_Calculate(int begin,uint8_t end,uint8_t (*p)[2]);
float Slope_Calculate_Lonest_White(int bigy,uint8_t smally,uint8_t (*p),bool flag);


//浮点曲率
float process_fcurvity(uint8_t (* ipts)[2],uint8_t m,uint8_t separate);//三点曲率计算
//整数曲率
int process_icurvity(unsigned char (* ipts)[2],unsigned char start, unsigned char separate);
uint16_t my_sqrt(uint32_t a); //快排     快速排序，对一个32位整数求平方根

#endif